package com.earl.eatbao.web;

import static org.slf4j.LoggerFactory.getLogger;

import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.earl.eatbao.commons.vo.ResultMessage;
import com.earl.eatbao.service.UserService;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

@RestController
@RequestMapping(value = "/admin")
public class AdminstorController extends BaseController {

    // desc:日记工具logger
    private static final Logger logger = getLogger(AdminstorController.class);

    @Autowired
    private UserService userService;
    
	/**
	 * 拉黑用户
	 * 
	 * @param userId
	 */
	@ApiOperation(value = "拉黑用户", notes = "拉黑用户", httpMethod = "POST", response = String.class)
	@RequestMapping(value="/takeback/{userId}",  method = RequestMethod.POST)
	public ResponseEntity<ResultMessage> takeBackUser(
			@ApiParam(name = "userId", required = true, value = "指点用户ID")
			@PathVariable
			Long userId){

        logger.info("<====== 进入takeBackUser:方法,{[userId] :" + userId + " } ====");
        // desc: 封装操作结果
        userService.takeBackUser(userId);
        ResultMessage result = new ResultMessage();
        result.setServiceResult(true);
        result.setMessageCode(200l);
        result.setResultInfo("请求操作成功");

        logger.info("==== 退出takeBackUser方法 返回值类型:{ ResponseEntity<ResultMessage>: } =======>");
        return new ResponseEntity<ResultMessage>(result, HttpStatus.OK);
	}

    /**
     * 解冻用户
     * @param userId
     * @return
     */
    @ApiOperation(value = "解冻用户", notes = "解冻用户", httpMethod = "POST", response = String.class)
    @RequestMapping(value="/unfreeze/{userId}",  method = RequestMethod.POST)
	public ResponseEntity<ResultMessage> unfreezeUser(
	        @ApiParam(name = "userId", required = true, value = "解冻用户的ID")
	        @PathVariable Long userId) {

        logger.info("<====== 进入unfreezeUser:方法,{[userId] :" + userId + " } ====");

        // desc: 封装操作结果
        ResultMessage result = new ResultMessage();
        userService.unfreezeUser(userId);
        result.setServiceResult(true);
        result.setMessageCode(200l);
        result.setResultInfo("请求操作成功");

        logger.info("==== 退出unfreezeUser方法 返回值类型:{ ResponseEntity<ResultMessage>: } =======>");
        return new ResponseEntity<ResultMessage>(result, HttpStatus.OK);
    }
}
